package cn.com.sparkle.paxos.net.protocolprocessor.filter;

import org.apache.log4j.Logger;

import cn.com.sparkle.paxos.net.frame.FrameBody;
import cn.com.sparkle.paxos.net.netlayer.PaxosSession;
import cn.com.sparkle.paxos.net.protocolprocessor.ProtocolProcessor;

public class ConnectCheckFilter implements ProtocolProcessor<FrameBody> {

	private final static ConnectCheckFilter instance = new ConnectCheckFilter();
	private final static Logger logger = Logger.getLogger(ConnectCheckFilter.class);

	public static ConnectCheckFilter getInstance() {
		return instance;
	}

	private ConnectCheckFilter() {
	}

	@Override
	public boolean receive(FrameBody body, PaxosSession session) {
		if (body.isValid()) {
			return false; // go to next process
		} else {
			logger.info("The checksum of Tcp  is invalid, close connection !");
			session.closeSession();
		}
		return true;
	}

	@Override
	public void onConnect(PaxosSession session) {
	}

	@Override
	public void onDisConnect(PaxosSession session) {
	}

}
